package com.vn.gofriends.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.vn.gofriends.R;
import com.vn.gofriends.item.Trip;

public class DiscoverAdapter extends ArrayAdapter<Trip> {

	ArrayList<Trip> myTrips;
	Context context;
	int resource;

	public DiscoverAdapter(Context context, int resource,
			ArrayList<Trip> myTrips) {
		super(context, resource, myTrips);
		this.myTrips = myTrips;
		this.context = context;
		this.resource = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			view = ((LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
					.inflate(resource, parent, false);
		}
		Trip myTrip = myTrips.get(position);
		if (myTrip != null) {
			TextView txtNameTrip = (TextView) view
					.findViewById(R.id.txtNameTrips);
			ImageView imgMyTrip = (ImageView) view.findViewById(R.id.imgTrips);
			TextView txtUsername = (TextView) view
					.findViewById(R.id.txtUsernameOwner);
			txtNameTrip.setText(myTrip.getTitle());
			txtUsername.setText(myTrip.getUserameOwner());
		}
		return view;
	}

}
